package com.fang.gulimall.admin.domain.system.role.db;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fang.gulimall.admin.domain.system.menu.db.SysMenuEntity;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @ClassName SysRoleMapper
 * @Description TODO
 * @Author fangge
 * @Date 2024/6/13 12:41
 */
public interface SysRoleMapper extends BaseMapper<SysRoleEntity> {

    /**
     * 根据角色ID查询对应的菜单权限
     *
     * @param roleId 角色ID
     * @return 权限列表
     */
    @Select("SELECT m.* "
            + "FROM sys_menu m "
            + " LEFT JOIN sys_role_menu rm ON m.menu_id = rm.menu_id "
            + " LEFT JOIN sys_role r ON r.role_id = rm.role_id "
            + "WHERE m.status = 1 AND m.deleted = 0 "
            + " AND r.status = 1 AND r.deleted = 0 "
            + " AND r.role_id = #{roleId}")
    List<SysMenuEntity> getMenuListByRoleId(Long roleId);

}